package com.poi.tl.sample.quickstart.app.tags;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.data.RowRenderData;
import com.deepoove.poi.data.Rows;
import com.deepoove.poi.data.Tables;
import com.poi.tl.sample.quickstart.consts.AppConsts;
import java.io.FileOutputStream;
import java.util.HashMap;
import org.springframework.core.io.ClassPathResource;

public class _4_2StyleTableExport {

  public static void main(String[] args) throws Exception {
    ClassPathResource templateFile = new ClassPathResource(AppConsts.TAG_TEMPLATE_CLASS_PATH + "_4table_template.docx");
    String outFile = AppConsts.EXPORT_PATH + "_4_2_style_table_template_output.docx";

    // 1 	compile 编译模板
    XWPFTemplate template = XWPFTemplate.compile(templateFile.getInputStream()).render(
        // 2 render 渲染数据
        new HashMap<String, Object>(){{
          // 第0行居中且背景为蓝色的表格
          RowRenderData row0 = Rows.of("姓名", "学历").textColor("FFFFFF")
              .bgColor("4472C4").center().create();
          RowRenderData row1 = Rows.create("李四", "博士");
          put("table0", Tables.create(row0, row1));
        }});
    // 3 write 输出到流
    template.writeAndClose(new FileOutputStream(outFile));
  }

}
